package com.tjbank.cssys.web.controller;

import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CkErrorLog;
import com.tjbank.cssys.domain.CkLog;
import com.tjbank.cssys.web.service.CkErrorLogService;
import com.tjbank.cssys.web.service.CkLogService;
import com.tjbank.cssys.web.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api(tags = "CkLogController", description = "日志配置")
@RestController
@RequestMapping("/log")
@Slf4j
public class CkLogController    {

    private  final  static Logger logger = LoggerFactory.getLogger(CkLogController. class);

    @Autowired
    private CkLogService ckLogService;
    @Autowired
    private CkErrorLogService ckErrorLogService;
/*
    static Logger log = Logger.getLogger(CkLogController.class);
*/

    @ApiOperation("获取 日志信息 查询管理")
    @PostMapping("/list")
    public CommonResult selectList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5")Integer pageSize, CkLog ckLog, HttpServletRequest request ){
        PageInfo pageData = ckLogService.selectList(page,pageSize,ckLog,request);
        return CommonResult.success(pageData,"查询成功！");
    }

    @ApiOperation(" 添加  日志信息管理")
    @PostMapping("/add")
    public CommonResult  add(CkLog ckLog, HttpServletRequest request){
        boolean b = ckLogService.addInsert(ckLog);
        if(b==true){
            return  CommonResult.success(b,"添加日志成功");
        }
        else{
            return  CommonResult.failed("添加日志失败");
        }
    }

    @ApiOperation("获取 错误日志信息 查询管理")
    @RequestMapping("/getErrorlist")
    public CommonResult getErrorList(CkErrorLog ckErrorLog ,Integer page,Integer pageSize  , HttpServletRequest request){
        PageInfo pageInfo = ckErrorLogService.selectError(ckErrorLog  , page ,pageSize,request);
        return  CommonResult.success(pageInfo);
    }

}
